package com.wish.g04.renting.service.impl;

import com.wish.g04.base.entity.MAttachment;
import com.wish.g04.base.entity.SfContract;
import com.wish.g04.base.service.IMAttachmentService;
import com.wish.g04.common.core.web.controller.BaseController;
import com.wish.g04.common.security.utils.SecurityUtils;
import com.wish.g04.renting.service.TMAttachmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.List;

/**
 * 这个类的作者是123
 * 开发的日期是：2022/05/31
 **/
@Service
public class TMAttachmentServiceimpl extends BaseController implements TMAttachmentService {
    @Autowired
    IMAttachmentService imAttachmentService;
    @Override
    public boolean saveAttachments(SfContract sfContract) {
        //保存附件
        List<MAttachment> attachmentList = sfContract.getAttachmentList();
        if (attachmentList!=null){
            for (MAttachment attachment : attachmentList) {
                //图片对象保存合同编号
                attachment.setRelationId(sfContract.getId());
                attachment.setCreateUserid(SecurityUtils.getUserId());
                attachment.setUpdateUserid(SecurityUtils.getUserId());
                //类型收房合同
                attachment.setRelationType(10);
                attachment.setCreateTime(LocalDateTime.now());
                attachment.setUpdateTime(LocalDateTime.now());
            }
            boolean b = imAttachmentService.saveBatch(attachmentList);
            return b;
        }
        return false;
    }
}
